package com.zhuozhou.jdyc.main.main.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.base.BaseRecyclerViewAdapter;
import com.zhuozhou.jdyc.base.BaseViewHolder;
import com.zhuozhou.jdyc.databinding.IndexMerchantItemBinding;
import com.zhuozhou.jdyc.main.main.bean.ShopIndexBean;
import com.zhuozhou.jdyc.util.apiUtil.StringUtil;

/**
 * Create by CherishTang on 2020/3/27 0027
 * describe:首页菜单adapter
 */
public class IndexMerchantAdapter extends BaseRecyclerViewAdapter<ShopIndexBean, IndexMerchantItemBinding> {
    public OnMerchantItemClickListener mOnMerchantItemClickListener;

    public IndexMerchantAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.index_merchant_item;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder baseViewHolder, int pos) {
        super.onBindViewHolder(baseViewHolder, pos);
        baseViewHolder.getBinding().getRoot().setOnClickListener(v -> {
            if (mOnMerchantItemClickListener != null) {
                mOnMerchantItemClickListener.onMerchantItemClick(baseViewHolder.getBinding().getRoot(), getRealPosition(baseViewHolder));
            }
        });
    }

    @Override
    public void onBindHolder(BaseViewHolder<IndexMerchantItemBinding> holder, int pos) {
        Glide.with(mContext).load(mList.get(pos).getImages()).into(holder.getBinding().imageMerchant);
        if (StringUtil.isEmpty(mList.get(pos).getName())) {
            mList.get(pos).setName(mList.get(pos).getLabel());
        }
        holder.getBinding().setShop(mList.get(pos));
    }

    public void setOnMerchantItemClickListener(OnMerchantItemClickListener l) {
        mOnMerchantItemClickListener = l;
    }

    public interface OnMerchantItemClickListener {
        void onMerchantItemClick(View view, int position);
    }
}
